From c9e5232d3bb25a56d2243e9927a9f834c51f687a Mon Sep 17 00:00:00 2001 From: "rac61@labyrinth.cl.cam.ac.uk" Date: Wed, 9 Jul 2003 09:16:48 +0000 Subject: [PATCH] bitkeeper revision 1.304.1.2 (3f0bdd80mrpM9InfprcL835uydvRVA) Small bug fix for Extent constructor parameter ordering Reformatting, cleanups, adjust the usage/help messages for Parse* to make more sense Make ParseHelp throw slightly less exceptions =) --- .../cmdline/ParseDomainDestroy.java | 48 +++--- .../xenoserver/cmdline/ParseDomainList.java | 65 ++++---- .../xenoserver/cmdline/ParseDomainNew.java | 144 ++++++++++-------- .../xenoserver/cmdline/ParseDomainStart.java | 46 +++--- .../xenoserver/cmdline/ParseDomainStop.java | 46 +++--- .../cmdline/ParseFailedException.java | 20 +-- .../src/org/xenoserver/cmdline/ParseHelp.java | 40 +++-- .../cmdline/ParsePartitionsAdd.java | 20 ++- .../cmdline/ParsePartitionsList.java | 83 +++++----- .../cmdline/ParsePhysicalGrant.java | 24 +-- .../xenoserver/cmdline/ParsePhysicalList.java | 119 +++++++++------ .../cmdline/ParsePhysicalRevoke.java | 70 +++++---- .../org/xenoserver/cmdline/ParseVdCreate.java | 84 +++++----- .../org/xenoserver/cmdline/ParseVdDelete.java | 61 ++++---- .../org/xenoserver/cmdline/ParseVdFree.java | 62 ++++---- .../xenoserver/cmdline/ParseVdRefresh.java | 71 +++++---- .../org/xenoserver/cmdline/ParseVdShow.java | 15 +- .../control/CommandPhysicalList.java | 8 +- .../org/xenoserver/control/VirtualDisk.java | 4 +- .../src/org/xenoserver/control/XMLHelper.java | 9 +- 20 files changed, 561 insertions(+), 478 deletions(-) diff --git a/tools/control/src/org/xenoserver/cmdline/ParseDomainDestroy.java b/tools/control/src/org/xenoserver/cmdline/ParseDomainDestroy.java index 799a953772..78d224cf5e 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainDestroy.java +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainDestroy.java @@ -7,32 +7,30 @@ import org.xenoserver.control.CommandFailedException; import org.xenoserver.control.Defaults; public class ParseDomainDestroy extends CommandParser { - public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException { - int domain_id = getIntParameter(args, 'n', 0); - boolean force = getFlagParameter(args, 'f'); + public void parse(Defaults d, LinkedList args) + throws ParseFailedException, CommandFailedException { + int domain_id = getIntParameter(args, 'n', 0); + boolean force = getFlagParameter(args, 'f'); - if (domain_id == 0) { - throw new ParseFailedException("Expected -n"); + if (domain_id == 0) { + throw new ParseFailedException("Expected -n"); + } + + String output = new CommandDomainDestroy(d, domain_id, force).execute(); + if (output != null) { + System.out.println(output); + } + } + + public String getName() { + return "destroy"; } - String output = new CommandDomainDestroy(d, domain_id, force).execute(); - if ( output != null ) - System.out.println( output ); - } - - public String getName() - { - return "destroy"; - } - - public String getUsage() - { - return "[-f] [-n]"; - } - - public String getHelpText() - { - return - "Destory the specified domain. -f forcibly destroys it."; - } + public String getUsage() { + return "-n [-f]"; + } + + public String getHelpText() { + return "Destroy the specified domain. -f forcibly destroys it."; + } } diff --git a/tools/control/src/org/xenoserver/cmdline/ParseDomainList.java b/tools/control/src/org/xenoserver/cmdline/ParseDomainList.java index bf36252e1d..4d3a1fecf1 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainList.java +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainList.java @@ -8,40 +8,37 @@ import org.xenoserver.control.Defaults; import org.xenoserver.control.Domain; public class ParseDomainList extends CommandParser { + public void parse(Defaults d, LinkedList args) + throws ParseFailedException, CommandFailedException { + CommandDomainList list = new CommandDomainList(d); + String output = list.execute(); + if (output != null) { + System.out.println(output); + } + + Domain[] domains = list.domains(); + + for (int loop = 0; loop < domains.length; loop++) { + System.out.println( + "id: " + domains[loop].id + " (" + domains[loop].name + ")"); + System.out.println(" processor: " + domains[loop].processor); + System.out.println(" has cpu: " + domains[loop].cpu); + System.out.println( + " state: " + domains[loop].nstate + " " + domains[loop].state); + System.out.println(" mcu advance: " + domains[loop].mcu); + System.out.println(" total pages: " + domains[loop].pages); + } + } + + public String getName() { + return "list"; + } + + public String getUsage() { + return ""; + } - public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException { - CommandDomainList list = new CommandDomainList(d); - String output = list.execute(); - if ( output != null ) - System.out.println( output ); - Domain[] domains = list.domains(); - - for (int loop = 0; loop < domains.length; loop++) - { - System.out.println ("id: " + domains[loop].id + - " (" + domains[loop].name+ ")"); - System.out.println (" processor: " + domains[loop].processor); - System.out.println (" has cpu: " + domains[loop].cpu); - System.out.println (" state: " + domains[loop].nstate + " " + - domains[loop].state); - System.out.println (" mcu advance: " + domains[loop].mcu); - System.out.println (" total pages: " + domains[loop].pages); + public String getHelpText() { + return "List domain information and status."; } - } - - public String getName() - { - return "list"; - } - - public String getUsage() - { - return ""; - } - - public String getHelpText() - { - return - "List domain information"; - } } diff --git a/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java b/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java index 069d439b16..080e8a3d2b 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java @@ -7,76 +7,86 @@ import org.xenoserver.control.CommandFailedException; import org.xenoserver.control.Defaults; public class ParseDomainNew extends CommandParser { + public void parse(Defaults d, LinkedList args) + throws ParseFailedException, CommandFailedException { + String name = getStringParameter(args, 'n', d.domainName); + int size = getIntParameter(args, 'k', d.domainSizeKB); + String image = getStringParameter(args, 'i', d.domainImage); + String initrd = getStringParameter(args, 'r', d.domainInitRD); + int vifs = getIntParameter(args, 'v', d.domainVIFs); + String bargs = getStringParameter(args, 'a', d.args) + " "; + String root_dev = getStringParameter(args, 'd', d.rootDevice); + String nfs_root_path = getStringParameter(args, 'f', d.nwNFSRoot); + String nw_ip = getStringParameter(args, '4', d.nwIP); + String nw_gw = getStringParameter(args, 'g', d.nwGateway); + String nw_mask = getStringParameter(args, 'm', d.nwMask); + String nw_nfs_server = getStringParameter(args, 's', d.nwNFSServer); + String nw_host = getStringParameter(args, 'h', d.nwHost); - public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException { - String name = getStringParameter(args, 'n', d.domainName); - int size = getIntParameter(args, 'k', d.domainSizeKB); - String image = getStringParameter(args, 'i', d.domainImage); - String initrd = getStringParameter (args, 'r', d.domainInitRD); - int vifs = getIntParameter(args, 'v', d.domainVIFs); - String bargs = getStringParameter (args, 'a', d.args) + " "; - String root_dev = getStringParameter (args, 'd', d.rootDevice); - String nfs_root_path = getStringParameter (args, 'f', d.nwNFSRoot); - String nw_ip = getStringParameter (args, '4', d.nwIP); - String nw_gw = getStringParameter (args, 'g', d.nwGateway); - String nw_mask = getStringParameter (args, 'm', d.nwMask); - String nw_nfs_server = getStringParameter (args, 's', d.nwNFSServer); - String nw_host = getStringParameter (args, 'h', d.nwHost); + d.describe(); - d.describe(); + CommandDomainNew c = + new CommandDomainNew( + d, + name, + size, + image, + initrd, + vifs, + bargs, + root_dev, + nfs_root_path, + nw_ip, + nw_gw, + nw_mask, + nw_nfs_server, + nw_host); + c.execute(); + String[] output = c.output(); + for (int i = 0; i < output.length; i++) { + System.out.println(output[i]); + } + } - CommandDomainNew c = new CommandDomainNew(d, name, size, image, initrd, vifs, - bargs, root_dev, nfs_root_path, - nw_ip, nw_gw, nw_mask, nw_nfs_server, nw_host); - c.execute(); - String[] output = c.output(); - for ( int i = 0; i < output.length; i++ ) - System.out.println( output[i] ); - } + public String getName() { + return "new"; + } - public String getName() - { - return "new"; - } + public String getUsage() { + return "[-n] [-k] [-i] [-v] [-r] [-d] [-f] [-s] [-4] [-g] [-m] [-h] [-a]"; + } - public String getUsage() - { - return "[-n] [-k] [-i] [-v] [-r] [-d] [-f] [-s] [-4] [-g] [-m] [-h] [-a]"; - } - - public String getHelpText() - { - return - "Create a new domain. Note that most of the parameters will assume\n" + - "default values: it should not be necessary to specify them all. See\n" + - "domctl.xml for the current default settings.\n" + - "\n" + - "General command line options:\n" + - " -n Domain name domain_name\n" + - " -k Domain size (kb) domain_size_kb\n" + - " -i Domain image name domain_image\n" + - " -v Number of VIFs domain_vifs\n" + - " -r InitRD (if required) domain_init_rd\n" + - " -d Root device (e.g /dev/nfs, /dev/hda3) root_device\n" + - " -a Additional boot parameters\n" + - "\n" + - "Networking options:\n" + - " -f NFS root (if /dev/nfs specified) nw_nfs_root\n" + - " -s NFS server nw_nfs_server\n" + - " -4 Domain IPv4 address nw_ip\n" + - " -g Domain gateway nw_gw\n" + - " -m Domain net mask nw_mask\n" + - " -h Domain hostname nw_host\n" + - "\n" + - "Parameters to -d, -f, -4, -g, -h can be specified as patterns into\n" + - "which the allocated domain ID will be incorporated. e.g. for\n" + - "domain 1 patterns would expand as follows:\n" + - "\n" + - " /dev/hda+ /dev/hda1\n" + - " /dev/hda7+ /dev/hda8\n" + - " 128.232.8.50+ 128.232.8.51\n" + - "\n" + - "Additionally, patterns for -4 -g -m can include an = which is\n" + - "expanded to the corresponding setting from the calling domain.\n"; - } + public String getHelpText() { + return "Create a new domain. Note that most of the parameters will assume\n" + + "default values: it should not be necessary to specify them all. See\n" + + "domctl.xml for the current default settings.\n" + + "\n" + + "General command line options:\n" + + " -n Domain name domain_name\n" + + " -k Domain size (kb) domain_size_kb\n" + + " -i Domain image name domain_image\n" + + " -v Number of VIFs domain_vifs\n" + + " -r InitRD (if required) domain_init_rd\n" + + " -d Root device (e.g /dev/nfs, /dev/hda3) root_device\n" + + " -a Additional boot parameters\n" + + "\n" + + "Networking options:\n" + + " -f NFS root (if /dev/nfs specified) nw_nfs_root\n" + + " -s NFS server nw_nfs_server\n" + + " -4 Domain IPv4 address nw_ip\n" + + " -g Domain gateway nw_gw\n" + + " -m Domain net mask nw_mask\n" + + " -h Domain hostname nw_host\n" + + "\n" + + "Parameters to -d, -f, -4, -g, -h can be specified as patterns into\n" + + "which the allocated domain ID will be incorporated. e.g. for\n" + + "domain 1 patterns would expand as follows:\n" + + "\n" + + " /dev/hda+ /dev/hda1\n" + + " /dev/hda7+ /dev/hda8\n" + + " 128.232.8.50+ 128.232.8.51\n" + + "\n" + + "Additionally, patterns for -4 -g -m can include an = which is\n" + + "expanded to the corresponding setting from the calling domain.\n"; + } } diff --git a/tools/control/src/org/xenoserver/cmdline/ParseDomainStart.java b/tools/control/src/org/xenoserver/cmdline/ParseDomainStart.java index 826057188f..e27394cb23 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainStart.java +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainStart.java @@ -7,32 +7,28 @@ import org.xenoserver.control.CommandFailedException; import org.xenoserver.control.Defaults; public class ParseDomainStart extends CommandParser { + public void parse(Defaults d, LinkedList args) + throws ParseFailedException, CommandFailedException { + int domain_id = getIntParameter(args, 'n', 0); - public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException { - int domain_id = getIntParameter(args, 'n', 0); - - if (domain_id == 0) { - throw new ParseFailedException("Expected -n"); + if (domain_id == 0) { + throw new ParseFailedException("Expected -n"); + } + + String output = new CommandDomainStart(d, domain_id).execute(); + if (output != null) + System.out.println(output); + } + + public String getName() { + return "start"; } - String output = new CommandDomainStart(d, domain_id).execute(); - if ( output != null ) - System.out.println( output ); - } - - public String getName() - { - return "start"; - } - - public String getUsage() - { - return "[-n]"; - } - - public String getHelpText() - { - return - "Start the specified domain."; - } + public String getUsage() { + return "-n"; + } + + public String getHelpText() { + return "Start the specified domain."; + } } diff --git a/tools/control/src/org/xenoserver/cmdline/ParseDomainStop.java b/tools/control/src/org/xenoserver/cmdline/ParseDomainStop.java index c2a9f1093b..306f18529b 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainStop.java +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainStop.java @@ -7,32 +7,28 @@ import org.xenoserver.control.CommandFailedException; import org.xenoserver.control.Defaults; public class ParseDomainStop extends CommandParser { + public void parse(Defaults d, LinkedList args) + throws ParseFailedException, CommandFailedException { + int domain_id = getIntParameter(args, 'n', 0); - public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException { - int domain_id = getIntParameter(args, 'n', 0); - - if (domain_id == 0) { - throw new ParseFailedException("Expected -n"); + if (domain_id == 0) { + throw new ParseFailedException("Expected -n"); + } + + String output = new CommandDomainStop(d, domain_id).execute(); + if (output != null) + System.out.println(output); + } + + public String getName() { + return "stop"; } - String output = new CommandDomainStop(d, domain_id).execute(); - if ( output != null ) - System.out.println( output ); - } - - public String getName() - { - return "stop"; - } - - public String getUsage() - { - return "[-n]"; - } - - public String getHelpText() - { - return - "Stop the specified domain."; - } + public String getUsage() { + return "-n"; + } + + public String getHelpText() { + return "Stop the specified domain."; + } } diff --git a/tools/control/src/org/xenoserver/cmdline/ParseFailedException.java b/tools/control/src/org/xenoserver/cmdline/ParseFailedException.java index 6e51be32a1..4f084cdb9b 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParseFailedException.java +++ b/tools/control/src/org/xenoserver/cmdline/ParseFailedException.java @@ -4,19 +4,11 @@ package org.xenoserver.cmdline; * Thrown when a command line could not be parsed. */ public class ParseFailedException extends Exception { - public ParseFailedException() { - super(); - } + public ParseFailedException(String message) { + super(message); + } - public ParseFailedException(String message) { - super(message); - } - - public ParseFailedException(String message, Throwable cause) { - super(message, cause); - } - - public ParseFailedException(Throwable cause) { - super(cause); - } + public ParseFailedException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/tools/control/src/org/xenoserver/cmdline/ParseHelp.java b/tools/control/src/org/xenoserver/cmdline/ParseHelp.java index a9a7138e85..8106116aaf 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParseHelp.java +++ b/tools/control/src/org/xenoserver/cmdline/ParseHelp.java @@ -5,31 +5,27 @@ import java.util.LinkedList; import org.xenoserver.control.Defaults; public class ParseHelp extends CommandParser { + public void parse(Defaults d, LinkedList args) { + if (args == null || args.isEmpty()) { + System.out.println("Usage:"); + Main.parser.printUsage(null); + } else { + System.out.print("xenctl "); + Main.parser.printHelpText(args); + } - public void parse(Defaults d, LinkedList args) { - if (args.size() == 0) { - System.out.println("Usage:"); - Main.parser.printUsage(null); - } else { - System.out.print("xenctl "); - Main.parser.printHelpText(args); + System.out.println(""); } - System.out.println(""); - } - - public String getName() - { - return "help"; - } + public String getName() { + return "help"; + } - public String getUsage() - { - return ""; - } + public String getUsage() { + return "[]"; + } - public String getHelpText() - { - return "This message"; - } + public String getHelpText() { + return "This message, or if a command is specified, help for that command."; + } } diff --git a/tools/control/src/org/xenoserver/cmdline/ParsePartitionsAdd.java b/tools/control/src/org/xenoserver/cmdline/ParsePartitionsAdd.java index 67e4902b9b..041e222b4f 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParsePartitionsAdd.java +++ b/tools/control/src/org/xenoserver/cmdline/ParsePartitionsAdd.java @@ -14,30 +14,34 @@ public class ParsePartitionsAdd extends CommandParser { public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException { boolean force = getFlagParameter(args, 'f'); String partition_name = getStringParameter(args, 'p', ""); - String size = getStringParameter(args, 'c', "100M"); + String size = getStringParameter(args, 'c', "128M"); - if (partition_name.equals("")) + if (partition_name.equals("")) { throw new ParseFailedException("Expected -p"); + } long chunksize = Library.parseSize( size ) / Settings.SECTOR_SIZE; - if ( chunksize <= 0 ) + if ( chunksize <= 0 ) { throw new CommandFailedException("Chunk size " + size + " is smaller than sector size."); + } // Initialise the partition manager and look up the partition loadState(); Partition p = PartitionManager.IT.getPartition(partition_name); - if ( p == null ) + if ( p == null ) { throw new CommandFailedException("Partition " + partition_name + " does not exist."); + } // Check if this partition belongs to the VDM - if (p.isXeno() && !force) + if (p.isXeno() && !force) { throw new CommandFailedException("Refusing to add partition as it is already allocated to the virtual disk manager. Use -f if you are sure."); + } String output = new CommandPartitionAdd( p, chunksize ).execute(); - if ( output != null ) + if ( output != null ) { System.out.println( output ); - + } saveState(); } @@ -46,7 +50,7 @@ public class ParsePartitionsAdd extends CommandParser { } public String getUsage() { - return "[-f] [-p] [-c]"; + return "-p [-f] [-c]"; } public String getHelpText() { diff --git a/tools/control/src/org/xenoserver/cmdline/ParsePartitionsList.java b/tools/control/src/org/xenoserver/cmdline/ParsePartitionsList.java index ac60c6e591..40388a7f5f 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParsePartitionsList.java +++ b/tools/control/src/org/xenoserver/cmdline/ParsePartitionsList.java @@ -10,45 +10,56 @@ import org.xenoserver.control.Partition; import org.xenoserver.control.PartitionManager; public class ParsePartitionsList extends CommandParser { - public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException { - loadState(); - Iterator i = PartitionManager.IT.iterator(); - int idx = 1; - System.out.println( " maj:min " + " blocks " + "start sect " + - " num sects " + "name" ); - while (i.hasNext()) { - Partition p = (Partition) i.next(); - - if (p.isXeno()) { - System.out.print("[ "); - } else { - System.out.print(" "); - } - System.out.print(Library.format(idx++, 2, false) + " "); - System.out.print(Library.format(p.getMajor(),3,false) + ":" + - Library.format(p.getMinor(),3,true) + " " + - Library.format(p.getBlocks(),10,false) + " " + - Library.format(p.getStartSect(),10,false) + " " + - Library.format(p.getNumSects(),10,false) + " " + - Library.format(p.getName(),7,true)); - if (p.isXeno()) { - System.out.println("]"); - } else { - System.out.println(); - } + public void parse(Defaults d, LinkedList args) + throws ParseFailedException, CommandFailedException { + loadState(); + Iterator i = PartitionManager.IT.iterator(); + int idx = 1; + System.out.println( + " maj:min " + + " blocks " + + "start sect " + + " num sects " + + "name"); + while (i.hasNext()) { + Partition p = (Partition) i.next(); + + if (p.isXeno()) { + System.out.print("[ "); + } else { + System.out.print(" "); + } + System.out.print(Library.format(idx++, 2, false) + " "); + System.out.print( + Library.format(p.getMajor(), 3, false) + + ":" + + Library.format(p.getMinor(), 3, true) + + " " + + Library.format(p.getBlocks(), 10, false) + + " " + + Library.format(p.getStartSect(), 10, false) + + " " + + Library.format(p.getNumSects(), 10, false) + + " " + + Library.format(p.getName(), 7, true)); + if (p.isXeno()) { + System.out.println("]"); + } else { + System.out.println(); + } + } } - } - public String getName() { - return "list"; - } + public String getName() { + return "list"; + } - public String getUsage() { - return ""; - } + public String getUsage() { + return ""; + } - public String getHelpText() { - return "List real partition information"; - } + public String getHelpText() { + return "List physical partition information. Partitions surrounded by [] are XenoPartitions."; + } } diff --git a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java index 629d2cb3bf..60cb925dd1 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java @@ -16,31 +16,37 @@ public class ParsePhysicalGrant extends CommandParser { String partition_name = getStringParameter(args, 'p', ""); boolean write = getFlagParameter(args, 'w'); - if (domain_id == 0) + if (domain_id == 0) { throw new ParseFailedException("Expected -n"); - if (partition_name.equals("")) + } + if (partition_name.equals("")) { throw new ParseFailedException("Expected -p"); + } Mode mode; - if (write) + if (write) { mode = Mode.READ_WRITE; - else + } else { mode = Mode.READ_ONLY; + } // Initialise the partition manager and look up the partition loadState(); Partition p = PartitionManager.IT.getPartition(partition_name); - if ( p == null ) + if ( p == null ) { throw new CommandFailedException("Partition " + partition_name + " does not exist."); + } // Check if this partition belongs to the VDM - if (p.isXeno() && !force) + if (p.isXeno() && !force) { throw new CommandFailedException("Refusing to grant physical access as the given partition is allocated to the virtual disk manager. Use -f if you are sure."); - + } + String output = new CommandPhysicalGrant( d, domain_id, p, mode ).execute(); - if ( output != null ) + if ( output != null ) { System.out.println( output ); + } } public String getName() { @@ -48,7 +54,7 @@ public class ParsePhysicalGrant extends CommandParser { } public String getUsage() { - return "[-f] [-w] [-n] [-p]"; + return "-n -p [-f] [-w]"; } public String getHelpText() { diff --git a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java index 18a4400e80..1b662aa069 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java @@ -13,59 +13,82 @@ import org.xenoserver.control.Partition; import org.xenoserver.control.PartitionManager; public class ParsePhysicalList extends CommandParser { + public void parse(Defaults d, LinkedList args) + throws ParseFailedException, CommandFailedException { + int domain_id = getIntParameter(args, 'n', 0); + if (domain_id == 0) { + throw new ParseFailedException("Expected -n"); + } - public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException { - int domain_id = getIntParameter(args, 'n', 0); - if (domain_id == 0) - throw new ParseFailedException("Expected -n"); + // Initialise the partition manager + loadState(); - // Initialise the partition manager - loadState(); - - CommandPhysicalList list = new CommandPhysicalList( d, domain_id ); - String output = list.execute(); - if ( output != null ) - System.out.println( output ); - - System.out.println( "maj:min " + " blocks " + "start sect " + - " num sects " + "name " + "access" ); - Iterator i = list.extents().entrySet().iterator(); - while ( i.hasNext() ) - { - Entry entry = (Entry) i.next(); - Extent e = (Extent) entry.getKey(); - String mode = entry.getValue().toString(); - Partition p = PartitionManager.IT.getPartition( e ); - if ( p != null ) { - System.out.println(Library.format(p.getMajor(),3,false) + ":" + - Library.format(p.getMinor(),3,true) + " " + - Library.format(p.getBlocks(),10,false) + " " + - Library.format(p.getStartSect(),10,false) + " " + - Library.format(p.getNumSects(),10,false) + " " + - Library.format(p.getName(),7,true) + " " + - Library.format(mode,2,true)); - } else { - System.out.println(Library.format(e.getMajor(),3,false) + ":" + - Library.format(e.getMinor(),3,true) + " " + - " " + " " + - Library.format(e.getOffset(),10,false) + " " + - Library.format(e.getSize(),10,false) + " " + - " " + " " + - Library.format(mode,2,true)); - } + CommandPhysicalList list = new CommandPhysicalList(d, domain_id); + String output = list.execute(); + if (output != null) { + System.out.println(output); + } + + System.out.println( + "maj:min " + + " blocks " + + "start sect " + + " num sects " + + "name " + + "access"); + Iterator i = list.extents().entrySet().iterator(); + while (i.hasNext()) { + Entry entry = (Entry) i.next(); + Extent e = (Extent) entry.getKey(); + String mode = entry.getValue().toString(); + Partition p = PartitionManager.IT.getPartition(e); + if (p != null) { + System.out.println( + Library.format(p.getMajor(), 3, false) + + ":" + + Library.format(p.getMinor(), 3, true) + + " " + + Library.format(p.getBlocks(), 10, false) + + " " + + Library.format(p.getStartSect(), 10, false) + + " " + + Library.format(p.getNumSects(), 10, false) + + " " + + Library.format(p.getName(), 7, true) + + " " + + Library.format(mode, 2, true)); + } else { + System.out.println( + Library.format(e.getMajor(), 3, false) + + ":" + + Library.format( + e.getMinor() | e.getPartitionNo(), + 3, + true) + + " " + + " " + + " " + + Library.format(e.getOffset(), 10, false) + + " " + + Library.format(e.getSize(), 10, false) + + " " + + " " + + " " + + Library.format(mode, 2, true)); + } + } } - } - public String getName() { - return "list"; - } + public String getName() { + return "list"; + } - public String getUsage() { - return "[-n]"; - } + public String getUsage() { + return "-n"; + } - public String getHelpText() { - return "List all physical access which the given domain has been granted."; - } + public String getHelpText() { + return "List all physical access which the given domain has been granted."; + } } diff --git a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java index a5c90a720d..1f075b4708 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java @@ -9,37 +9,43 @@ import org.xenoserver.control.Partition; import org.xenoserver.control.PartitionManager; public class ParsePhysicalRevoke extends CommandParser { - public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException { - int domain_id = getIntParameter(args, 'n', 0); - String partition_name = getStringParameter(args, 'p', ""); - - if (domain_id == 0) - throw new ParseFailedException("Expected -n"); - if (partition_name.equals("")) - throw new ParseFailedException("Expected -p"); - - // Initialise the partition manager and look up the partition - loadState(); - Partition p = PartitionManager.IT.getPartition(partition_name); - - if ( p == null ) - throw new CommandFailedException("Partition " + partition_name + " does not exist."); - - String output = new CommandPhysicalRevoke( d, domain_id, p ).execute(); - if ( output != null ) - System.out.println( output ); - } - - public String getName() { - return "revoke"; - } - - public String getUsage() { - return "[-n] [-p]"; - } - - public String getHelpText() { - return "Revoke access to the given partition from the specified domain."; - } + public void parse(Defaults d, LinkedList args) + throws ParseFailedException, CommandFailedException { + int domain_id = getIntParameter(args, 'n', 0); + String partition_name = getStringParameter(args, 'p', ""); + + if (domain_id == 0) { + throw new ParseFailedException("Expected -n"); + } + if (partition_name.equals("")) { + throw new ParseFailedException("Expected -p"); + } + + // Initialise the partition manager and look up the partition + loadState(); + Partition p = PartitionManager.IT.getPartition(partition_name); + + if (p == null) { + throw new CommandFailedException( + "Partition " + partition_name + " does not exist."); + } + + String output = new CommandPhysicalRevoke(d, domain_id, p).execute(); + if (output != null) { + System.out.println(output); + } + } + + public String getName() { + return "revoke"; + } + + public String getUsage() { + return "-n -p"; + } + + public String getHelpText() { + return "Revoke access to the given partition from the specified domain."; + } } diff --git a/tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java b/tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java index 4f4210f22f..3aaeb967ac 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java @@ -1,5 +1,7 @@ package org.xenoserver.cmdline; +import java.text.DateFormat; +import java.text.ParseException; import java.util.Date; import java.util.LinkedList; @@ -10,40 +12,52 @@ import org.xenoserver.control.Library; import org.xenoserver.control.Settings; public class ParseVdCreate extends CommandParser { - public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException { - String name = getStringParameter(args,'n',""); - String size_s = getStringParameter(args,'s',""); - String expiry_s = getStringParameter(args,'e',""); - Date expiry; - - if ( name.equals("") ) - throw new ParseFailedException("Expected -n"); - if ( size_s.equals("") ) - throw new ParseFailedException("Expected -s"); - if ( expiry_s.equals("") ) - expiry = null; - else - expiry = new Date(Date.parse(expiry_s)); - - long size = Library.parseSize(size_s); - - loadState(); - String output = new CommandVdCreate(name,size/Settings.SECTOR_SIZE,expiry).execute(); - if ( output != null ) - System.out.println( output ); - saveState(); - } - - public String getName() { - return "create"; - } - - public String getUsage() { - return "[-n] [-s] [-e]"; - } - - public String getHelpText() { - return "Create a new virtual disk with the specified parameters"; - } + public void parse(Defaults d, LinkedList args) + throws ParseFailedException, CommandFailedException { + String name = getStringParameter(args, 'n', ""); + String size_s = getStringParameter(args, 's', ""); + String expiry_s = getStringParameter(args, 'e', ""); + Date expiry; + + if (name.equals("")) { + throw new ParseFailedException("Expected -n"); + } + if (size_s.equals("")) { + throw new ParseFailedException("Expected -s"); + } + if (expiry_s.equals("")) { + expiry = null; + } else { + DateFormat format = DateFormat.getDateTimeInstance(); + try { + expiry = format.parse(expiry_s); + } catch (ParseException e) { + throw new ParseFailedException("Could not parse date"); + } + } + + long size = Library.parseSize(size_s); + + loadState(); + String output = + new CommandVdCreate(name, size / Settings.SECTOR_SIZE, expiry) + .execute(); + if (output != null) { + System.out.println(output); + } + saveState(); + } + + public String getName() { + return "create"; + } + + public String getUsage() { + return "-n -s [-e]"; + } + + public String getHelpText() { + return "Create a new virtual disk with the specified parameters"; + } } diff --git a/tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java b/tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java index bcd400876e..6d4f838c4e 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java @@ -8,33 +8,38 @@ import org.xenoserver.control.Defaults; import org.xenoserver.control.VirtualDiskManager; public class ParseVdDelete extends CommandParser { - public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException { - String vd_key = getStringParameter(args,'k',""); - - if ( vd_key.equals("") ) - throw new ParseFailedException("Expected -k"); - - loadState(); - if ( VirtualDiskManager.IT.getVirtualDisk(vd_key) == null ) - throw new CommandFailedException("Virtual disk " + vd_key + " does not exist"); - - String output = new CommandVdDelete(vd_key).execute(); - if ( output != null ) - System.out.println( output ); - - saveState(); - } - - public String getName() { - return "delete"; - } - - public String getUsage() { - return "[-k]"; - } - - public String getHelpText() { - return "Deletes the virtual disk with the specified key."; - } + public void parse(Defaults d, LinkedList args) + throws ParseFailedException, CommandFailedException { + String vd_key = getStringParameter(args, 'k', ""); + + if (vd_key.equals("")) { + throw new ParseFailedException("Expected -k"); + } + + loadState(); + if (VirtualDiskManager.IT.getVirtualDisk(vd_key) == null) { + throw new CommandFailedException( + "Virtual disk " + vd_key + " does not exist"); + } + + String output = new CommandVdDelete(vd_key).execute(); + if (output != null) { + System.out.println(output); + } + + saveState(); + } + + public String getName() { + return "delete"; + } + + public String getUsage() { + return "-k"; + } + + public String getHelpText() { + return "Deletes the virtual disk with the specified key."; + } } diff --git a/tools/control/src/org/xenoserver/cmdline/ParseVdFree.java b/tools/control/src/org/xenoserver/cmdline/ParseVdFree.java index ea62f8998f..bd7826bfab 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParseVdFree.java +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdFree.java @@ -12,34 +12,44 @@ import org.xenoserver.control.VirtualDisk; import org.xenoserver.control.VirtualDiskManager; public class ParseVdFree extends CommandParser { - public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException { - boolean verbose = getFlagParameter(args, 'v'); - - loadState(); - VirtualDisk free = VirtualDiskManager.IT.getFreeDisk(); - System.out.println( "Free disk has " + free.getExtentCount() + " extents totalling " - + Library.formatSize(free.getSize()*Settings.SECTOR_SIZE,8,true) ); - if ( verbose ) { - Iterator i = free.extents(); - System.out.println(" disk offset size"); - while (i.hasNext()) { - Extent e = (Extent) i.next(); - System.out.println( Library.format(e.getDisk(), 6, false) + " " - + Library.format(e.getOffset(), 12, false) + " " - + Library.format(e.getSize(), 12, false) ); - } + public void parse(Defaults d, LinkedList args) + throws ParseFailedException, CommandFailedException { + boolean verbose = getFlagParameter(args, 'v'); + + loadState(); + VirtualDisk free = VirtualDiskManager.IT.getFreeDisk(); + System.out.println( + "Free disk has " + + free.getExtentCount() + + " extents totalling " + + Library.formatSize( + free.getSize() * Settings.SECTOR_SIZE, + 8, + true)); + if (verbose) { + Iterator i = free.extents(); + System.out.println(" disk offset size"); + while (i.hasNext()) { + Extent e = (Extent) i.next(); + System.out.println( + Library.format(e.getDisk(), 6, false) + + " " + + Library.format(e.getOffset(), 12, false) + + " " + + Library.format(e.getSize(), 12, false)); + } + } } - } - public String getName() { - return "free"; - } + public String getName() { + return "free"; + } - public String getUsage() { - return "[-v]"; - } + public String getUsage() { + return "[-v]"; + } - public String getHelpText() { - return "Show free space allocated to virtual disk manager. -v enables verbose output."; - } + public String getHelpText() { + return "Show free space allocated to virtual disk manager. -v enables verbose output."; + } } diff --git a/tools/control/src/org/xenoserver/cmdline/ParseVdRefresh.java b/tools/control/src/org/xenoserver/cmdline/ParseVdRefresh.java index be5a36616e..e578099e53 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParseVdRefresh.java +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdRefresh.java @@ -1,5 +1,7 @@ package org.xenoserver.cmdline; +import java.text.DateFormat; +import java.text.ParseException; import java.util.Date; import java.util.LinkedList; @@ -8,35 +10,44 @@ import org.xenoserver.control.CommandVdRefresh; import org.xenoserver.control.Defaults; public class ParseVdRefresh extends CommandParser { - public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException { - String vd_key = getStringParameter(args,'k',""); - String expiry_s = getStringParameter(args,'e',""); - Date expiry; - - if ( vd_key.equals("") ) - throw new ParseFailedException("Expected -k"); - if ( expiry_s.equals("") ) - expiry = null; - else - expiry = new Date(Date.parse(expiry_s)); - - loadState(); - String output = new CommandVdRefresh(vd_key,expiry).execute(); - if ( output != null ) - System.out.println(output); - saveState(); - } - - public String getName() { - return "refresh"; - } - - public String getUsage() { - return "-k [-e]"; - } - - public String getHelpText() { - return "Refresh the expiry for the specified virtual disk. Omitting -e will cause the disk to never expire."; - } + public void parse(Defaults d, LinkedList args) + throws ParseFailedException, CommandFailedException { + String vd_key = getStringParameter(args, 'k', ""); + String expiry_s = getStringParameter(args, 'e', ""); + Date expiry; + + if (vd_key.equals("")) { + throw new ParseFailedException("Expected -k"); + } + if (expiry_s.equals("")) { + expiry = null; + } else { + DateFormat format = DateFormat.getDateTimeInstance(); + try { + expiry = format.parse(expiry_s); + } catch (ParseException e) { + throw new ParseFailedException("Could not parse date"); + } + } + + loadState(); + String output = new CommandVdRefresh(vd_key, expiry).execute(); + if (output != null) { + System.out.println(output); + } + saveState(); + } + + public String getName() { + return "refresh"; + } + + public String getUsage() { + return "-k [-e]"; + } + + public String getHelpText() { + return "Refresh the expiry for the specified virtual disk. Omitting -e will cause the disk to never expire."; + } } diff --git a/tools/control/src/org/xenoserver/cmdline/ParseVdShow.java b/tools/control/src/org/xenoserver/cmdline/ParseVdShow.java index af65573902..a833d26405 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParseVdShow.java +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdShow.java @@ -23,23 +23,26 @@ public class ParseVdShow extends CommandParser { while ( i.hasNext() ) { VirtualDisk vd = (VirtualDisk) i.next(); System.out.print( vd.getKey() + " " ); - if ( vd.getExpiry() != null ) + if ( vd.getExpiry() != null ) { System.out.print( vd.getExpiry().toString() ); - else + } else { System.out.print( " " ); + } System.out.println( " " + Library.format(vd.getName(),16,true) + " " + Library.formatSize(vd.getSize()*Settings.SECTOR_SIZE,8,false) ); } } else { VirtualDisk vd = VirtualDiskManager.IT.getVirtualDisk(key); - if ( vd == null ) + if ( vd == null ) { throw new CommandFailedException("There is no virtual disk " + key ); + } System.out.println(" name: " + vd.getName()); System.out.println(" key: " + vd.getKey()); System.out.println(" size: " + Library.formatSize(vd.getSize()*Settings.SECTOR_SIZE,8,true)); - if ( vd.getExpiry() != null ) + if ( vd.getExpiry() != null ) { System.out.println("expiry: " + vd.getExpiry()); + } System.out.println(); Iterator i = vd.extents(); @@ -58,10 +61,10 @@ public class ParseVdShow extends CommandParser { } public String getUsage() { - return "[-n]"; + return "[-k]"; } public String getHelpText() { - return "Show a summary of all virtual disks, or details of one disk if -n is given"; + return "Show a summary of all virtual disks, or details of one disk if -k is given"; } } diff --git a/tools/control/src/org/xenoserver/control/CommandPhysicalList.java b/tools/control/src/org/xenoserver/control/CommandPhysicalList.java index 14c9288db4..b4c96f2698 100644 --- a/tools/control/src/org/xenoserver/control/CommandPhysicalList.java +++ b/tools/control/src/org/xenoserver/control/CommandPhysicalList.java @@ -65,12 +65,16 @@ public class CommandPhysicalList extends Command { outline = in.readLine(); while (outline != null) { int disk = -1; + int partition_no = -1; long offset = -1; long size = -1; StringTokenizer st = new StringTokenizer(outline); if (st.hasMoreTokens()) { - disk = Short.parseShort(st.nextToken(), 16); + disk = Integer.parseInt(st.nextToken(), 16); + } + if (st.hasMoreTokens()) { + partition_no = Integer.parseInt(st.nextToken(), 16); } if (st.hasMoreTokens()) { offset = Long.parseLong(st.nextToken(), 16); @@ -80,7 +84,7 @@ public class CommandPhysicalList extends Command { } if (st.hasMoreTokens()) { String mode = st.nextToken(); - Extent extent = new Extent(disk, offset, size); + Extent extent = new Extent(disk, offset, size, partition_no); if (mode.equals("rw")) { map.put(extent, Mode.READ_WRITE); } else if (mode.equals("r")) { diff --git a/tools/control/src/org/xenoserver/control/VirtualDisk.java b/tools/control/src/org/xenoserver/control/VirtualDisk.java index 70f61f4779..8bacadbb49 100644 --- a/tools/control/src/org/xenoserver/control/VirtualDisk.java +++ b/tools/control/src/org/xenoserver/control/VirtualDisk.java @@ -169,8 +169,8 @@ public class VirtualDisk { Extent extent = new Extent( partition.getDisk(), - extentSize, - partition.getStartSect() + (extentSize * loop)); + partition.getStartSect() + (extentSize * loop), + extentSize); addExtent(extent); } diff --git a/tools/control/src/org/xenoserver/control/XMLHelper.java b/tools/control/src/org/xenoserver/control/XMLHelper.java index d495eb9c2c..1f93844dd2 100644 --- a/tools/control/src/org/xenoserver/control/XMLHelper.java +++ b/tools/control/src/org/xenoserver/control/XMLHelper.java @@ -146,10 +146,11 @@ class XMLHelper { XMLHelper.getSubNode("disk", enode))), Long.parseLong( XMLHelper.getText( - XMLHelper.getSubNode("size", enode))), - Long.parseLong( - XMLHelper.getText( - XMLHelper.getSubNode("offset", enode)))); + XMLHelper.getSubNode("offset", enode))), + Long.parseLong( + XMLHelper.getText( + XMLHelper.getSubNode("size", enode)))); + vd.addExtent(extent); } } -- 2.30.2